#include <openssl/md5.h>
#include <htmlcxx/html/ParserDom.h>
#include <memory>
#include <pcrecpp.h>
#include "main.h"
#include "database.h"
#include "site.h"
#include "wcurl.h"
#include "config.h"
#include "thr.h"
#include "glb.h"

cthread::cthread()
{
}

cthread::~cthread()
{

}



void cthread::thread_main()
{
    bool     flip=false;
    mysqlcls db;

    db.connect(GCFG->_mitza.host.c_str(),GCFG->_mitza.user.c_str(),GCFG->_mitza.password.c_str());

    //cout << " T {"<< _hthread <<"\n";
    while(__alive)
    {
        uripage* p = glb::dequeue();
        if(0==p)
        {
            if(flip){
                flip=!flip;
                GLOGI("Idling...\n");
            }
            sleep(1);
            continue;
        }
        flip=true;
        p->create(&db);
        glb::remove(p->_uri);
        delete p;
        usleep(0xFFFF);
    }
    db.disconnect();
    GLOGT("T exiting");
    //cout << " T }"<< _hthread <<"\n";
}



